package com.metaera.app.controller;

import com.metaera.app.R;
import com.metaera.app.controller.core.RequestPresenter;
import com.metaera.app.controller.core.SimplePaginationPresenter;
import com.metaera.app.controller.view.BasicPaginationView;
import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.controller.view.core.IPaginationView;

import androidx.lifecycle.Lifecycle;

public class PresenterFactory {

    private PresenterFactory() {

    }

    public static <T> RequestPresenter<INetworkRequestView<T>> get(
            RequestPresenter<INetworkRequestView<T>> presenter,
            INetworkRequestView<T> view,
            Lifecycle lifecycle) {

        lifecycle.addObserver(presenter);
        presenter.setModelAndView(view);
        return presenter;
    }


    public static <T> RequestPresenter<IPaginationView<T>> get(
            RequestPresenter<IPaginationView<T>> presenter,
            IPaginationView<T> view,
            Lifecycle lifecycle) {

        lifecycle.addObserver(presenter);
        presenter.setModelAndView(view);
        return presenter;
    }


    public static <T> RequestPresenter<IPaginationView<T>> get(
            SimplePaginationPresenter<T> presenter,
            BasicPaginationView<T> view,
            Lifecycle lifecycle) {

        lifecycle.addObserver(presenter);

        view.setEmptyLayoutResId(R.layout.view_state_layout_empty); // 空内容
        view.setNotMoreFooterLayoutResId(R.layout.view_list_not_more); // 没有更多
        presenter.setModelAndView(view);
        return presenter;
    }

}
